| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkAstraeus::MaterialManager Class Referencefinal

Manages the materials available in the component. More...

Inheritance diagram for nkAstraeus::MaterialManager:

## Public Member Functions
virtual | ~MaterialManager ()
Material * | createOrRetrieve (nkMemory::StringView name, MATERIAL_TYPE type)
Material * | record (nkMemory::StringView name, nkMemory::UniquePtr< Material > resource)
Material * | get (nkMemory::StringView name)
Material * | getByIndex (unsigned int id)
void | rename (nkMemory::StringView currentName, nkMemory::StringView newName)
void | erase (nkMemory::StringView name)
nkMemory::UniquePtr< Material > | relinquish (nkMemory::StringView name)

## Detailed Description

Manages the materials available in the component.

At all times, manager owns any memory allocated inside. External code should never delete memory returned by it.

## Constructor & Destructor Documentation

## ◆ ~MaterialManager()

virtual nkAstraeus::MaterialManager::~MaterialManager | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ createOrRetrieve()

Material* nkAstraeus::MaterialManager::createOrRetrieve | ( | nkMemory::StringView | name,
|  | MATERIAL_TYPE | type
| ) |  |

Creates if unavailable, or retrieves if available, a material.

Depending on the parameter given for the type, the Material instance retrieved will be :

Value | Pointer type
--- | ---
MATERIAL_TYPE::PBS | PbsMaterial

To address it fully, casting is required. For instance :

PbsMaterial* mat = (PbsMaterial*)MaterialManager::getInstance()->createOrRetrieve("mat", MATERIAL_TYPE::PBS) ;

Parameters

  name | The name of the material to retrieve.
  type | The material type to create.

Returns
  The material requested, possibly freshly created. The manager owns the memory returned, external code should never delete it. See erase().

## ◆ record()

Material* nkAstraeus::MaterialManager::record | ( | nkMemory::StringView | name,
|  | nkMemory::UniquePtr< Material > | resource
| ) |  |

Records an already existing resource in the manager, passing its ownership around.

Parameters

  name | The name under which the resource should be recorded.
  resource | The resource to record.

Returns
  A raw pointer over the resource, now recorded in the manager.

## ◆ get()

Material* nkAstraeus::MaterialManager::get | ( | nkMemory::StringView | name | ) |

Retrieves a material.

Parameters

  name | The name of the material to retrieve.

Returns
  The material requested if available, nullptr else.

## ◆ getByIndex()

Material* nkAstraeus::MaterialManager::getByIndex | ( | unsigned int | id | ) |

Get a material, by index. Note that one index can map to a different material after memory is changed. Useful to loop over all available materials in one go.

Parameters

  id | The index of the material to retrieve.

Returns
  The material linked if available, nullptr else.

## ◆ rename()

void nkAstraeus::MaterialManager::rename | ( | nkMemory::StringView | currentName,
|  | nkMemory::StringView | newName
| ) |  |

Renames a material.

Parameters

  currentName | The name of the material to rename.
  newName | The name to reassign to the material.

## ◆ erase()

void nkAstraeus::MaterialManager::erase | ( | nkMemory::StringView | name | ) |

Erases and frees a material.

Parameters

  name | The name of the material to erase.

## ◆ relinquish()

nkMemory::UniquePtr<Material> nkAstraeus::MaterialManager::relinquish | ( | nkMemory::StringView | name | ) |

Requests the manager to relinquish the ownership of a resource and pass it around.

Parameters

  name | The name of the recorded resource to relinquish.

Returns
  The ownership over the resource requested if available, nullptr otherwise.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsAstraeus/Graphics/Materials/MaterialManager.h